<!DOCTYPE html>
<!--在html中引入此命名空间，可避免编辑器出现html验证错误，虽然加不加命名空间对Thymeleaf的功能没有任何影响。-->
<html>
<head>
    <meta charset="UTF-8">
    <title>商品详情</title>
    <!--jquery-->
    <script type="text/javascript" src="jquery/jquery-3.6.0.js"></script>
    <!--bootstrap-->
    <link rel="stylesheet" type="text/css" href="bootstrap-3.4.1/bootstrap.css">
    <script type="text/javascript" src="bootstrap-3.4.1/bootstrap.js"></script>
    <!--jquery-validator-->
    <script type="text/javascript" src="jquery-validation/jquery.validate.js"></script>
    <script type="text/javascript" src="jquery-validation/localization/messages_zh.js"></script>
    <!--jquery-json-->
    <script type="text/javascript" src="jquery/json/jquery.json.min.js"></script>
    <!--md5-->
    <script type="text/javascript" src="md5/md5.js"></script>
    <!--common-->
    <script type="text/javascript" src="js/common.js"></script>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-heading">秒杀订单详情</div>
    <table class="table" id="order">
        <tr>
            <td>商品名称</td>
            <td id="goodsName" colspan="2"></td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td colspan="2"><img id="goodsImg" width="200" height="200"/></td>
        </tr>
        <tr>
            <td>订单价格</td>
            <td id="goodsPrice" colspan="2"></td>
        </tr>
        <tr>
            <td>下单时间</td>
            <td id="createDate" colspan="2"></td>
        </tr>
        <tr>
            <td>订单状态</td>
            <td id="status">
                <!--<span if="${order.status eq 0}">未支付</span>
                <span if="${order.status eq 1}">待发货</span>
                <span if="${order.status eq 2}">已发货</span>
                <span if="${order.status eq 3}">已收货</span>
                <span if="${order.status eq 4}">已退款</span>
                <span if="${order.status eq 5}">已完成</span>-->
            </td>
            <td>
                <button class="btn btn-primary btn-block" type="submit" id="payButton">立即支付</button>
            </td>
        </tr>
        <tr>
            <td>收货人</td>
            <td colspan="2">XXX 18012345678</td>
        </tr>
        <tr>
            <td>收货地址</td>
            <td colspan="2">上海市浦东区世纪大道</td>
        </tr>
    </table>
</div>
</body>

<script>
    $(function () {
        getOrderDetail();
    });


    function getOrderDetail() {
        var orderId = getQueryString("orderId");
        $.ajax({
            url: 'order/detail',
            type: 'GET',
            data: {
                orderId: orderId
            },
            success: function (data) {
                if (data.code == 200) {
                    render(data.obj);
                } else {
                    alert(data.message);
                }
            },
            error: function () {

            }
        });
    }

    function render(orderDetail) {
        var goods = orderDetail.goods;
        var order = orderDetail.order;
        $("#goodsName").text(goods.goodsName);
        $("#goodsImg").attr("src", goods.goodsImg);
        $("#goodsPrice").text(order.goodsPrice);
        $("#createDate").text(new Date(order.createDate).format("yyyy-MM-dd HH:mm:ss"));
        var status = order.status;
        var statusText = "";
        switch (status) {
            case 0:
                statusText = "未支付";
                break;
            case 1:
                statusText = "待发货";
                break;
            case 2:
                statusText = "已发货";
                break;
            case 3:
                statusText = "已收货";
                break;
            case 4:
                statusText = "已退款";
                break;
            case 5:
                statusText = "已完成";
                break;
        }
        $("#status").text(statusText);
    }
</script>
</html>